<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app"></div>

  <template id="my-app">
    <h2>{{fullName}}</h2>
    <button @click="changeFirstName()">修改</button>
  </template>

  <script src="../js/vue.js"></script>
  <script>
    const App = {
      template: "#my-app",
      data() {
        return {
          firstName: "kobe",
          lastName: "Bryant",
        }
      },
      computed: {
        fullName: {
          get: function () {
            return this.firstName + " " + this.lastName;
          },
          set: function (value) {
            console.log(value);
            // const names = value.split(" ");
            // this.firstName = names[0];
            // this.firstName = names[1];
            this.firstName = value;
          }
        }
      },
      methods: {
        changeFirstName() {
          this.fullName = "coder why"
        },
      },
    };

    Vue.createApp(App).mount("#app");
  </script>
</body>

</html>